﻿@model GitCandy.Models.BranchSelectorModel
@{
    var values = ViewContext.RouteData.Values;
    var action = values["action"] as string;
    var noLink = Model.Path == null;
    var identity = Html.GetRootViewBag().Identity++;
}
<div class="dropdown btn-group">
    <a class="btn btn-default" data-toggle="dropdown"><i class="@Model.CurrentIsBranch.ToFlagString("glyphicon glyphicon-random", "glyphicon glyphicon-tag")"></i><span class="branch-name"> @Model.Current</span></a>
    <a href="#" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
    <div class="dropdown-menu">
        <form>
            <ul class="nav nav-tabs nav-justified">
                <li class="@Model.CurrentIsBranch.ToFlagString("active", "")"><a href="#branch-pane-@identity" data-toggle="tab">@SR.Repository_Branches</a></li>
                <li class="@Model.CurrentIsBranch.ToFlagString("", "active")"><a href="#tag-pane-@identity" data-toggle="tab">@SR.Repository_Tags</a></li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane @Model.CurrentIsBranch.ToFlagString("active", "") branch-selector" id="branch-pane-@identity">
                    <ul class="nav nav-list">
                        @foreach (var branch in Model.Branches)
                        {
                            if (noLink)
                            {
                                <li><a href="#">@branch</a></li>
                            }
                            else if (branch == Model.Current)
                            {
                                <li class="active"><a>@branch</a></li>
                            }
                            else
                            {
                                <li>@Html.ActionLink(branch, action, Html.OverRoute(new { path = branch + "/" + Model.Path }))</li>
                            }
                        }
                    </ul>
                </div>
                <div class="tab-pane @Model.CurrentIsBranch.ToFlagString("", "active") branch-selector" id="tag-pane-@identity">
                    <ul class="nav nav-list">
                        @foreach (var tag in Model.Tags)
                        {
                            if (noLink)
                            {
                                <li><a href="#">@tag</a></li>
                            }
                            else if (tag == Model.Current)
                            {
                                <li class="active"><a>@tag</a></li>
                            }
                            else
                            {
                                <li>@Html.ActionLink(tag, action, Html.OverRoute(new { path = tag + "/" + Model.Path }))</li>
                            }
                        }
                    </ul>
                </div>
            </div>
        </form>
    </div>
</div>
